;  This file is part of tornado.
; 
;    tornado is free software: you can redistribute it And/Or modify
;    it under the terms of the GNU General Public License As published by
;    the Free Software Foundation, either version 3 of the License, Or
;    any later version.
; 
;    tornado is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE.  See the
;    GNU General Public License For more details.
; 
;    You should have received a copy of the GNU General Public License
;    along With tornado.  If Not, see <http://www.gnu.org/licenses/>. 2
; 


; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Macro new(struct)
  AllocateMemory(SizeOf( struct )) 
EndMacro

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
#PACKET_LIMIT = 2048 ; UDP SIZE

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Enumeration $10
  #PACKET_SYSTEM
  #PACKET_CUSTOM
;   #PACKET_FILE_CHUNK
EndEnumeration

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Enumeration 01
  #TYPE_ASCII  
  #TYPE_BYTE  
  #TYPE_CHAR  
  #TYPE_WORD  
  #TYPE_UNICODE  
  #TYPE_INTEGER
  #TYPE_FLOAT
  #TYPE_DOUBLE
  #TYPE_QUAD
  #TYPE_LONG    
  #TYPE_STRING
  #TYPE_STRUCT
EndEnumeration

; /////////////////////////////////////////////////////////////////////////////
; client protocol
; /////////////////////////////////////////////////////////////////////////////
Enumeration 01 
  #CLIENT_REQUEST_INFO        ; client request server information ( max player , player list , protected , game version , party name , etc...)
  #CLIENT_TRY_TO_CONNECT      ; client try to connect
  #CLIENT_SEND_ALIVE_SIGNAL   ; client send alive signal
  #CLIENT_SEND_PONG           ; after receive ping, client send a pong
  #CLIENT_SEND_GIVE_MY_PING   ; client want to known the ping
  #CLIENT_SEND_DISCONNECT 
  #CLIENT_SEND_CHANGE_NICKNAME
EndEnumeration 



Enumeration 01
  #SERVER_SEND_BAD_GUID       ; wrong game unique id
  #SERVER_SEND_BAD_VERSION    ; wrong game version
  #SERVER_SEND_BAD_GAMENAME   ; wrong game version
  #SERVER_SEND_BAD_PASSWORD   ; wrong password
  #SERVER_SEND_BAN_BY_IP      ; ban by ip
  #SERVER_SEND_BAN_BY_PSEUDO  ; ban by pseudo
  #SERVER_SEND_FULL           ; server is full
  #SERVER_SEND_SLOT           ; server send slot to the client
  #SERVER_SEND_UPDATE_LIST    ; new client arrive, server advise all client
  #SERVER_SEND_INFORMATION    ; server send information about current game
  #SERVER_SEND_PING           ; server send ping every 3000 ms
  #SERVER_SEND_PING_FOR_SLOT
  #SERVER_SEND_PLAYER_CONNECTED
  #SERVER_SEND_PLAYER_DISCONNECTED
  #SERVER_SEND_PLAYER_CHANGE_NICKNAME
  #SERVER_SEND_KICK
  #SERVER_SEND_PLAYER_HAS_BEEN_KICKED
EndEnumeration


Enumeration $FF
  #TORNADO_EVENT_NONE
  #TORNADO_EVENT_PLAYER_CONNECTED
  #TORNADO_EVENT_PLAYER_DISCONNECTED
  #TORNADO_EVENT_RECEIVE_PING
  #TORNADO_EVENT_PLAYER_CHANGE_NICKNAME
  #TORNADO_EVENT_LOOSE_CONNECTION
  #TORNADO_EVENT_KICKED
  #TORNADO_EVENT_PLAYER_KICKED
EndEnumeration
; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sPacket
  *mData
  mOffset.l
  mIsValid.b
  mDestination.i
  mFromIP.s
EndStructure

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sPacketManager
  mCustomTimer.i
  mSystemTimer.i
  List *mCustomPacket.sPacket()
  List *mSystemPacket.sPacket()
EndStructure

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sBanned
  mReason.s
  mTime.l
EndStructure
; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sTornadoServerClient
  mClientID.i
  mAliveTimer.i
  mClientPseudo.s
  mCanAdmin.a
  mPingMarker.i
  mPongMarker.i
  mPing.i
  mIsActive.b
EndStructure

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sTornadoClientInfo
  mClientPseudo.s
  mCanAdmin.a
  mPing.l
  mIsActive.b
EndStructure


; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sTornadoServerCmd
  
EndStructure

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sTornadoServer
  mGUID.s
  mName.s
  mVersion.s
  mMaxPlayer.l
  mPassword.s
  mConnectionID.i
  mPacketManager.sPacketManager
  mSystemPacketTimer.i
  List mCustomPacketReceived.sPacket()
  List mSystemPacketReceived.sPacket()
  mUnBanTimer.i
  Map mBannedIP.sBanned()
  Map mBannedPseudo.sBanned()
  mNbPlayer.l
  Array mClientSlot.sTornadoServerClient(1)
  mPingTimer.l
  mLastConnectedSlot.l
  mLastDisConnectedSlot.l
  mClientUpdate.b
  mEvent.l
  mEventSlot.l
  mAdminPassword.s
  Map mCmd.i()
  
EndStructure

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sClientJoinError
  mErrorCode.l
  mErrorMessage.s
EndStructure

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sTornadoClient
  mClientID.i
  mPseudo.s
  mPassword.s
  mGUID.s
  mJoinError.s
  mSlot.l
  mPacketManager.sPacketManager
  Array mClientSlot.sTornadoClientInfo(1)
  mLastPingRequest.i
  mAliveTimer.i
  mLastConnectedSlot.l
  mLastDisConnectedSlot.l
  mClientUpdate.b
  mEvent.l
  mEventSlot.l
  mFirstCall.b
  List mCustomPacketReceived.sPacket()
  List mSystemPacketReceived.sPacket()
EndStructure

; /////////////////////////////////////////////////////////////////////////////
;
; /////////////////////////////////////////////////////////////////////////////
Structure sServerInformation
  mNbPlayer.l
  mMaxPlayer.l
  mProtect.a 
  mName$
  mVersion$ 
  mIP$
  mPort.w
EndStructure
